package com.liuzh.deviceinfo.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import c.h.a.m0.h;
import c.h.a.m0.i;
import c.h.a.n0.c;
import c.h.a.n0.d;
import c.h.a.n0.e;
import c.h.a.q;

public class SettingsItemView extends ConstraintLayout {
    public static final /* synthetic */ int z = 0;
    public TextView t = ((TextView) findViewById(2131297054));
    public TextView u = ((TextView) findViewById(2131297011));
    public ImageView v = ((ImageView) findViewById(2131296628));
    public int w;
    public b x;
    public a y;

    public interface a {
    }

    public interface b {
    }

    public SettingsItemView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, 0);
        ViewGroup.inflate(getContext(), 2131493043, this);
        int t = h.t(12.0f, getResources().getDisplayMetrics());
        setPadding(t, t, t, t);
        setMinHeight(h.t(48.0f, getResources().getDisplayMetrics()));
        TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, q.e);
        String string = obtainStyledAttributes.getString(7);
        String string2 = obtainStyledAttributes.getString(6);
        this.v.setImageDrawable(obtainStyledAttributes.getDrawable(0));
        this.t.setText(string);
        if (TextUtils.isEmpty(string2)) {
            this.u.setVisibility(8);
        } else {
            this.u.setText(string2);
        }
        int i = obtainStyledAttributes.getInt(8, 0);
        if (i != 0) {
            FrameLayout frameLayout = (FrameLayout) findViewById(2131297339);
            if (i == 1) {
                ViewGroup.inflate(getContext(), 2131493044, frameLayout);
                Switch switchR = (Switch) findViewById(2131296903);
                String string3 = obtainStyledAttributes.getString(3);
                if (obtainStyledAttributes.hasValue(5)) {
                    boolean z = obtainStyledAttributes.getBoolean(5, false);
                    if (!isInEditMode()) {
                        i iVar = i.a;
                        iVar = i.a;
                        z = i.b.getBoolean(string3, z);
                    }
                    switchR.setChecked(z);
                    switchR.setOnCheckedChangeListener(new d(this, string3));
                    setOnClickListener(new e(switchR));
                } else {
                    throw new IllegalArgumentException(c.b.a.a.a.D("SwitchWidget type need siv_sp_default_val for key = ", string3));
                }
            } else if (i == 2) {
                k(obtainStyledAttributes);
            }
        } else {
            findViewById(2131297339).setVisibility(8);
        }
        this.w = i;
        obtainStyledAttributes.recycle();
    }

    public final void k(TypedArray typedArray) {
        String string = typedArray.getString(3);
        if (typedArray.hasValue(4)) {
            int i = typedArray.getInt(4, 0);
            CharSequence[] textArray = typedArray.getTextArray(1);
            int[] intArray = getResources().getIntArray(typedArray.getResourceId(2, 0));
            i iVar = i.a;
            iVar = i.a;
            int i2 = i.b.getInt(string, i);
            int i3 = 0;
            while (i3 < intArray.length) {
                if (intArray[i3] == i2) {
                    break;
                }
                i3++;
            }
            i3 = 0;
            this.u.setVisibility(0);
            this.u.setText(textArray[i3]);
            setOnClickListener(new c(this, string, i, intArray, textArray));
            return;
        }
        throw new IllegalArgumentException(c.b.a.a.a.D("SwitchWidget type need siv_sp_default_val for key = ", string));
    }

    public void setOnClickListener(OnClickListener onClickListener) {
        if (this.w != 1) {
            super.setOnClickListener(onClickListener);
            return;
        }
        throw new IllegalStateException("switchWidget type can't set clickListener");
    }

    public void setSelectListener(a aVar) {
        this.y = aVar;
    }

    public void setSwitchListener(b bVar) {
        if (this.w == 1) {
            this.x = bVar;
            return;
        }
        throw new UnsupportedOperationException("type不是switch，不支持设置switchListener");
    }
}
